public class OverrideView
{
     public String UrlId
    {
        get{        
                return System.currentPageReference().getParameters().get('id');     
           }  
        set;
    }    
    public OverrideView(ApexPages.StandardController controller){
        this.controller=controller;
    }
    
    public PageReference newview()
    {
        Message__c msg=[select Id,name,content__c from Message__c where Id=:UrlId];
        List<MessageRecipient__c> MsgList=[select Id,Recipient__c,Message__c,status__c from MessageRecipient__c where Message__c=:UrlId and Recipient__c=:UserInfo.getUserId()];
       
        if(MsgList!=NULL)
        {
            for(MessageRecipient__c mr:MsgList)
            {
                mr.Status__c='已读';
            }
            update MsgList;
        }
        
       // PageReference pr=new PageReference('/'+string.valueof(UrlId).trim()+'&nooverride=1');
        // system.assert(false,pr);
        PageReference pr=new PageReference('/'+urlid+'?retURL=%2F'+urlid+'&nooverride=1');
        pr.setRedirect(true);
        return pr;
    }
    private final ApexPages.StandardController controller;
    
    static testMethod void OverrideViewTest()
    {
        Message__c add = new Message__c();
        add.name = 'a';
        insert add;
    
        ApexPages.StandardController del = new ApexPages.StandardController(add);   
        
        OverrideView testCase = new OverrideView(del);
        
        test.setCurrentPageReference(Page.OverrideViewButton);
        System.currentPageReference().getParameters().put('id', add.Id); 
        testCase.newview(); 
        
            
    }
    
    
    
}